class DerivedClassName(Base1,Base2,. . ): Methods ------------- -------------
class circle: def setradius(self,r): self.r=r def area(self): a=3.14*self.r**2 print("Area is ",a) class xcircle(circle): def circumference(self): c=2*3.14*self.r print("circumference is ",c) a=circle() a.setradius(5) a.area() b=xcircle() b.setradius(2) b.area() b.circumference()
Area is 78.5 Area is 6.28 Circumference is 6.28
class Employee: def setData(self,n,s,a): self.name=n self.salary=s self.advance=a def showData(self): print("Name is ",self.name) print("Salary is ",self.salary) print("Advance is ",self.advance) class AEmployee(Employee): def payment(self): p=self.salary - self.advance print("Payment is ",p) a=Employee() a.setData("Amit",25000,5000) a.showData() b=AEmployee() b.setData("Gopal",40000,500) b.showData() b.payment()
Name is Amit Salary is 25000 Advance is 5000 Name is Gopal Salary is 40000 Advance is 500 Payment is 39500
class Account: def open(self,an,bl): self.accno=an self.bal=bl def deposit(self,amt): self.bal=self.bal+amt def withdraw(self,amt): self.bal=self.bal-amt def showBalance(self): print("AccNo is ",self.accno) print("Bal is ",self.bal) class SAccount(Account): def addInterest(self,r,n): si=self.bal*r*n/100 self.bal=self.bal+si a=Account() a.open(4117,25000) a.deposit(3000) a.withdraw(8000) a.showBalance() b=SAccount() b.open(3012,10000) b.deposit(40000) b.showBalance() b.addInterest(10.25,3) b.showBalance()
AccNo is 4117 Balance is 20000 AccNo is 3012 Balance is 50000 AccNo is 3012 Balance is 65375.50
class Rectangle : def setDimension(self,x,y): self.length = x self.breadth = y def area(self): a=self.length * self.breadth print("Area is ",a) class ARectangle(Rectangle): def perimeter(self): p=2*(self.length + self.breadth) print("Perimeter is ",p) a = Rectangle() a.setDimension(5,7) a.area() b = ARectangle() b.setDimension(10,20) b.area() b.perimeter()
Area is 35 Area is 200 Perimeter is 60